<template>
  <div>
    <el-dialog
      :title="examineTitle"
      :close-on-click-modal="false"
      :visible.sync="examineForm.examineFormDialog"
      width="800px"
      @close="closeDialog"
      center>
      <el-form
        :model="examineForm"
        :rules="examineFormRules"
        size="small"
        label-width="130px">
        <el-form-item label="审核意见" prop="name">
          <el-input v-model="examineForm.examineText" placeholder="请填写审核意见"></el-input>
        </el-form-item>
        <div class="text-align-right">
          <el-form-item>
            <el-button size="medium" @click="examine(false)">不通过</el-button>
            <el-button size="medium" type="primary" @click="examine(true)">通过</el-button>
          </el-form-item>
        </div>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
  import {confirmHandle} from "@/utils";

  export default {
    name: "examineDialog",
    props: ['examineDialog', 'examineTitle'],
    data() {
      return {
        examineForm: {
          examineFormDialog: false,
          examineText: ''
        },
        examineFormRules: {
          examineText: [
            {required: true, message: '请填写审核意见', trigger: 'blur'}
          ],
        },
      }
    },
    watch: {
      examineDialog() {
        this.examineForm.examineFormDialog = this.examineDialog;
      }
    },
    activated() {
    },
    methods: {
      examine(status) {
        const examineInfo = {
          examineStatus: status,
          examineText: this.examineForm.examineText
        }
        const examineText = examineInfo.examineStatus ? '通过' : '驳回';
        confirmHandle({label: `是否确定要${examineText}${this.examineTitle} ？`}).then(() => {
          this.$emit('change', examineInfo);
          this.examineForm.examineText = '';
        }).catch(() => {
        });
      },
      closeDialog() {
        this.examineForm.examineText = '';
        this.$emit('change', {
          examineStatus: false,
          examineText: ''
        });
      }
    }
  }
</script>

<style scoped>

</style>
